package com.test.controller.page;

import com.test.entity.AuthUser;
import com.test.service.AuthService;
import com.test.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/page/user")
public class UserPageController {
    @Resource
    BookService bookService;
    @Resource
    AuthService authService;
    @RequestMapping("/index")
    public String index(HttpSession session, Model model){
        model.addAttribute("user",authService.findUser(session));
        model.addAttribute("bookList",bookService.getAllBookWithOutBorrow());
        System.out.println(authService.findUser(session));
        return "user/index";
    }
    @RequestMapping("/book")
    public String book(HttpSession session,Model model){
        AuthUser user=authService.findUser(session);
        model.addAttribute("user",user);
        model.addAttribute("bookList",bookService.getAllBorrowBookById(user.getId()));
        System.out.println(authService.findUser(session));
        return "user/book";
    }
}
